﻿using System.Windows.Input;
using Cirrious.MvvmCross.Commands;
using TeaLightV5.Foundation.BL;
using TeaLightV5.Foundation.Sal.Interfaces;
using TeaLightV5.Foundation.UX.Interfaces.Models;

namespace TeaLightV5.Foundation.UX.ViewModels
{
    public abstract class ListEntityViewModel<T, TE, TV, TKey> 
        : EntityViewModel<TE, TKey>
        where T : IEntityModel<TE, TKey>, new()
        where TE : class, IEntity<TKey>, new()
        where TV : BaseEntityViewModel<T, TE, TKey>, new()
    {
        protected ListEntityViewModel()
        {
            
        }

        public virtual BaseEntityViewModelObservableCollection<T, TE, TV, TKey> Data 
        { 
            get 
            {
                return new BaseEntityViewModelObservableCollection<T, TE, TV, TKey>(Repository.GetAll()); 
            } 
        }

        public abstract ICommand ItemSelectedCommand { get; }

        public abstract ICommand AddCommand { get; }

        public ICommand RefreshCommand
        {
            get
            {
                return new MvxRelayCommand(ReloadModel);
            }
        }

        public override void ReloadModel()
        {
            RaisePropertyChanged("Data");
        }

    }
}
